-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix not thread safe xmlSchemaParse calls in ZTS builds by calling xmlSchemaInitTypes during MINIT #20150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e0908b7
to
8507bcc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The proper location for this would be in ext/libxml/libxml.c
. The reason is that multiple extensions expose schema functionality, not just DOM.
So the solution is, more specifically, replacing the following code:
Line 936 in 8507bcc
xmlInitParser(); |
such that it calls
xmlSchemaInitTypes
when libxml is compiled with schemas, and xmlInitParser
(like it does now) otherwise. (You don't need the ZTS check for this). Note that xmlSchemaInitTypes
will call xmlInitParser
.While at it, you can search the code for more calls to
xmlSchemaInitTypes
/ xmlInitParser
and remove them, such that the ext/libxml initialization routine is the only location.
🫡 I can do that, I'll reply when it's ready for a re-review. |
8507bcc
to
47ebdfc
Compare
Just pushed. Tested locally and when I did |
Thanks! That's what I actually thought of.
Quite interesting actually. Which version of libxml are you testing on? xmlInitParser();
#ifdef LIBXML_SCHEMAS_ENABLED
xmlSchemaInitTypes();
#endif |
Ah, no, I'm saying for my ease of testing I was doing:
as my "pre-fix" scenario to make it easy to swap back and forth and reproduce the error + confirm the fix fixes it (in lieu of more repeatable tests). I can swap to what you're suggesting for older versions though, I can probably get this PR updated and tested with that sometime tomorrow. |
Okay I see!
Yeah that would be preferable after all. I should've checked the earlier versions too before making my initial suggestion. |
…SchemaInitTypes during MINIT. See: https://gitlab.gnome.org/GNOME/libxml2/-/issues/930
47ebdfc
to
c625d91
Compare
Pushed up, tested locally, seems happy with this changeset as well. Lemme know if you want anything else! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, thanks.
We may need more initialization calls, e.g. it seems that xmlRelaxNGInitTypes
has the same issue. I'll take care of that.
On master we should remove other calls lingering around to xmlInitParser & co. I'll take care of that as well.
Follow-up for phpGH-20150.
See: https://gitlab.gnome.org/GNOME/libxml2/-/issues/930
I was getting a segfault in a ZTS build with:
Upon digging in, it looks like xmlSchemaParse is only thread safe if you call
xmlSchemaInitTypes
pre-threading / during init. I left out any call toxmlSchemaCleanupTypes
due to 8742276, which would "normally" take care of this kind of thing, and as far as I can tell we haven't been calling cleanup in any way forever, so I'm trying to minimize changes here. If y'all think it's necessary I'm happy to adjust.Locally, I haven't seen it crop up post-fix, but pre-fix it was occurring ~1/5th of the time when I was replicating by having https://github.com/php/frankenphp run phpunit in multiple threads.
Lemme know if I'm missing anything in making a PR here or if you want anything more rigorous than this.